package com.example.project.projectspringcloud.controller.front.sys;

import com.example.project.projectspringcloud.common.Constants;
import com.example.project.projectspringcloud.controller.BaseController;
import com.example.project.projectspringcloud.entity.RespBody;
import com.example.project.projectspringcloud.entity.sys.SysConfig;
import com.example.project.projectspringcloud.service.sys.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 前端系统控制器
 */
@Api(tags = "前端系统控制器")
@Controller
@RequestMapping(value = "/sysconfig")
public class ConfigController extends BaseController {

    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 公开api-获取配置
     * @param sysConfig
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "API获取系统配置", notes = "获取系统配置api")
    @GetMapping(value = "/api/get")
    @ResponseBody
    public RespBody get(SysConfig sysConfig) throws Exception {
        // 约束普通用户可见配置, 获取普通用户可见配置类型
        SysConfig normalUserCanShowTypes = sysConfigService.get(new SysConfig(Constants.SysConfigType.SYS_CONFIG_NORMAL_USER));
        sysConfig.setTypes(normalUserCanShowTypes.getValue());
        sysConfig = sysConfigService.get(sysConfig);
        return RespBody.ok(sysConfig);
    }
}
